<?xml version="1.0" encoding="UTF-8"?>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://xmlns.jcp.org/jsf/html"
      xmlns:f="http://xmlns.jcp.org/jsf/core">
    
    <h:head>
        <title>Companhia ES</title>
        <meta http-equiv="Context-Type" content="text/html; charset=UTF-8"/>
    </h:head>
    <h:body>
        <h1>Cadastro de departamentos</h1>
        
        <h:form id="edicao">
            <h:messages/>
            <h:inputHidden value="#{departamentoBean.departamento.id}"/>
            <h:panelGrid columns="2">
                <h:outputLabel value="Nome" for="nome"/>
                <h:inputText id="nome" value="#{departamentoBean.departamento.nome}" rendered="true"/>
                <h:commandButton value="Salvar" action="#{departamentoBean.salvar()}">
                    <f:ajax execute="@form" render=":edicao :listagem"/>
                </h:commandButton>
            </h:panelGrid>
        </h:form>
        
        <h:form id="listagem">
            <h:dataTable value="#{departamentoBean.lista}" var="departamento" rendered="#{!empty departamentoBean.lista}">
                <h:column>
                    <f:facet name="header">Nome</f:facet>
                    #{departamento.nome}
                </h:column>
                <h:column>
                    <h:commandLink>
                        <f:ajax execute="@this" render=":edicao"/>
                        <h:graphicImage library="imagens" name="edit.png"/>
                        <f:setPropertyActionListener target="#{departamentoBean.departamento}" value="#{departamento}"/>
                    </h:commandLink>
                </h:column>
                <h:column>
                    <h:commandLink action="#{departamentoBean.excluir()}">
                        <f:ajax execute="@this" render=":listagem"/>
                        <h:graphicImage library="imagens" name="excluir.png"/>
                        <f:setPropertyActionListener target="#{departamentoBean.departamento}" value="#{departamento}"/>
                    </h:commandLink>
                </h:column>
            </h:dataTable>
        </h:form>
    </h:body>
</html>
